*partisan identification (1 = strong democrat; 7 = strong republican)
gen pid = . 
replace pid = 1 if Q2 == 1 & Q3 == 1
replace pid = 2 if Q2 == 1 & Q3 == 2
replace pid = 3 if Q2 > 2 & Q5 == 1
replace pid = 4 if Q2 > 2 & Q5 == 2
replace pid = 5 if Q2 > 2 & Q5 == 3
replace pid = 6 if Q2 == 2 & Q4 == 2
replace pid = 7 if Q2 == 2 & Q4 == 1

*conditions
gen control = 0
replace control = 1 if condition == "control RD" | condition == "control RR"

gen wm_it = 0
replace wm_it = 1 if condition == "WM IT RD" | condition == "WM IT RR"

gen wm_pt = 0
replace wm_pt = 1 if condition == "WM PT RD" | condition == "WM PT RR"

gen dem_condition = 0
replace dem_condition = 1 if party == "Democrat"

gen rep_condition = 0
replace rep_condition = 1 if party == "Republican"

*drop respondents from different study not used in experiment
keep if wm_it == 1| wm_pt == 1 | control == 1

*empathy for individual in video - index

gen Q79_r = .
replace Q79_r = 1 if Q79_i == 5
replace Q79_r = 2 if Q79_i == 4
replace Q79_r = 3 if Q79_i == 3
replace Q79_r = 4 if Q79_i == 2
replace Q79_r = 5 if Q79_i == 1

gen ind_empathy = Q79_r + Q75_i + Q78_i
replace ind_empathy = . if control == 1 

*attention check
gen check_1 = 0
replace check_1 = 1 if Q138 == 1
gen check_2 = 0
replace check_2 = 1 if Q191 == 4
gen check = check_1 + check_2

*affective polarization variable 
rename Q18_4 FT_dems
rename Q18_5 FT_reps
gen affect = .
replace affect = FT_dems -FT_reps if dem_condition == 1
replace affect = FT_reps-FT_dems if rep_condition == 1

*demographic variables - using data collected by qualtrics, not data provided by Lucid

*white non hispanic dummy variable
gen white_nh = 0
replace white_nh = 1 if Q184 == 2 & Q185 == "1"
replace white_nh = . if Q184 > 1000 | Q185 == "."

*gender dummy - 1 = male
gen male = .
replace male = 1 if Q183 == 1
replace male = 0 if Q183 != 1 & Q183 < 1000

*female dummy
gen female = . 
replace female = 1 if Q183 == 2
replace female = 0 if Q183 != 2 & Q183 < 1000

*age variable
rename Q182 age_q
destring age_q, replace

*education variable
rename Q186 education_q

*ideology variable
rename Q52 ideology

*ideology variable, reverse coded
gen ideology_r = .
replace ideology_r = 1 if ideology == 7
replace ideology_r = 2 if ideology == 6
replace ideology_r = 3 if ideology == 5
replace ideology_r = 4 if ideology == 4
replace ideology_r = 5 if ideology == 3
replace ideology_r = 6 if ideology == 2
replace ideology_r = 7 if ideology == 1

*awareness variable - awareness_p is based on work of PE Jones. See here:
*https://www.pejones.org/publication/2022_jop/

*variables 1-5 are knowledge variables, and 6-7 are interest variables. 1-5
*are coded so that 1 = correct answer, 0 otherwise. 6 and 7 are scaled 0-1, where
*1 indicates greatest interest


gen a1 = 0
gen a2 = 0
gen a3 = 0
gen a4 = 0
gen a5 = 0
gen a6 = 0
gen a7 = 0

replace a1 = 1 if Q2_k == 2
replace a1 = . if Q2_k > 1000
replace a2 = 1 if Q4_k == 3
replace a2 = . if Q4_k > 1000
replace a3 = 1 if Q3_k == 3
replace a3 = . if Q3_k > 1000
replace a4 = 1 if Q5_k == 2
replace a4 = . if Q5_k > 1000
replace a5 = 1 if Q6_k == 2
replace a5 = . if Q6_k > 1000

replace a6 = 1 if Q112 == 1
replace a6 = .75 if Q112 == 2
replace a6 = .5 if Q112 == 3
replace a6 = .25 if Q112 == 4
replace a6 = 0 if Q112 == 5
replace a6 = . if Q112 > 1000

replace a7 = 1 if Q113 == 1
replace a7 = .5 if Q113 == 2
replace a7 = 0 if Q113 == 3
replace a7 = . if Q113 > 1000

gen awareness_add = a1 + a2 + a3 + a4 + a5 + a6 + a7
tab awareness_add

gen awareness_p = .
replace awareness_p = 1.39  if awareness_add == 0
replace awareness_p = 2.54  if awareness_add == .25
replace awareness_p =  3.12 if awareness_add == .5
replace awareness_p =  3.77 if awareness_add == .75
replace awareness_p =  5.41 if awareness_add == 1
replace awareness_p =  7.38 if awareness_add == 1.25
replace awareness_p =  8.37 if awareness_add == 1.5
replace awareness_p =  9.76 if awareness_add == 1.75
replace awareness_p =  15.09 if awareness_add == 2
replace awareness_p = 19.44  if awareness_add == 2.25
replace awareness_p =  20.34 if awareness_add == 2.5
replace awareness_p = 23.46  if awareness_add == 2.75
replace awareness_p = 30.68  if awareness_add == 3
replace awareness_p = 36.51  if awareness_add == 3.25
replace awareness_p =  37.57 if awareness_add == 3.5
replace awareness_p =  41.92 if awareness_add == 3.75
replace awareness_p =  48.89 if awareness_add == 4
replace awareness_p = 55.46  if awareness_add == 4.25
replace awareness_p = 57.10  if awareness_add == 4.5
replace awareness_p =  63.00 if awareness_add == 4.75
replace awareness_p = 69.98  if awareness_add == 5
replace awareness_p = 74.65  if awareness_add == 5.25
replace awareness_p = 75.23  if awareness_add == 5.5
replace awareness_p =  81.87 if awareness_add == 5.75
replace awareness_p = 90.24  if awareness_add == 6
replace awareness_p = 93.11  if awareness_add == 6.25
replace awareness_p =  93.52 if awareness_add == 6.5
replace awareness_p =  97.37 if awareness_add == 6.75
replace awareness_p =  100 if awareness_add == 7

gen awareness_pp = awareness_p/100
drop awareness_p
rename awareness_pp awareness_p

*GEI variable

alpha Q54 Q55 Q56 Q57, std 
factor Q54 Q55 Q56 Q57, ml
rotate, varimax
predict GEI_factor, regression

egen GEI_min = min(GEI_factor)
gen GEI_factor_final2 = GEI_factor-GEI_min
egen GEI_max = max(GEI_factor_final2)
gen GEI_factor_final = GEI_factor_final2/GEI_max
drop GEI_factor
rename GEI_factor_final GEI_factor
*this creates a GEI variable based on factor scores for the four items,
*rescaled to 0 through 1

*rename dependent variables
rename Q326 DV_rep_1
rename Q115 DV_rep_2
rename Q114 DV_rep_3
gen DV_rep_3_binary = .
replace DV_rep_3_binary = 1 if DV_rep_3 == 1
replace DV_rep_3_binary = 0 if DV_rep_3 > 1 & DV_rep_3 < 7

rename Q116 DV_rep_4
rename Q117 DV_rep_5
rename Q118 DV_rep_6
rename Q328 DV_rep_7

rename Q123 DV_dem_1
rename Q124 DV_dem_2
rename Q125 DV_dem_3
gen DV_dem_3_binary = .
replace DV_dem_3_binary = 1 if DV_dem_3 == 1
replace DV_dem_3_binary = 0 if DV_dem_3 > 1 & DV_dem_3 < 7
rename Q126 DV_dem_4

*reset DV_rep_1 and DV_dem_1 to 0-10 scales (as opposed to 1-11 scale)
rename DV_rep_1 DV_rep_1_unadjusted
rename DV_dem_1 DV_dem_1_unadjusted
gen DV_rep_1 = DV_rep_1_unadjusted - 1
gen DV_dem_1 = DV_dem_1_unadjusted - 1


*tables and figures

*table 2

 eststo clear
 gen flag = 0 
replace flag = 1 if rep_condition == 1 & wm_pt == 1
replace flag = 1 if rep_condition == 1 & wm_it == 1
regress ind_empathy wm_pt white_nh male age_q education_q ideology_r if flag == 1, vce(robust)
est sto m1

 eststo clear
 drop flag
 gen flag = 0 
replace flag = 1 if dem_condition == 1 & wm_pt == 1
replace flag = 1 if dem_condition == 1 & wm_it == 1
regress ind_empathy wm_pt white_nh male age_q education_q ideology_r if flag == 1, vce(robust)
est sto m2

esttab m1 m2 using table.rtf, b(2) se(2) r2 aic bic replace

*figure 1
 eststo clear
 drop flag
 gen flag = 0 
replace flag = 1 if rep_condition == 1 & control == 1
replace flag = 1 if rep_condition == 1 & wm_pt == 1
replace flag = 1 if rep_condition == 1 & wm_it == 1
regress DV_rep_1 wm_pt wm_it white_nh male age_q education_q ideology_r if flag == 1, vce(robust)
est sto m1
margins, dydx(wm_pt wm_it ideology_r)  post
est sto f1

 drop flag
 gen flag = 0 
replace flag = 1 if dem_condition == 1 & control == 1
replace flag = 1 if dem_condition == 1 & wm_pt == 1
replace flag = 1 if dem_condition == 1 & wm_it == 1
regress DV_dem_1 wm_pt wm_it white_nh male age_q education_q ideology_r if flag == 1, vce(robust)
est sto m2
margins, dydx(wm_pt wm_it ideology_r)  post
est sto f2

coefplot (f1, label(Republicans) mcolor(red) msymbol(circle_hollow) ciopts(lcol(red))) ///
 (f2 , label(Democrats) mcolor(blue) msymbol(triangle_hollow) ciopts(lcol(blue))), ///
   scheme(s1color) vertical yline(0, lpattern(dash)) ///
 ytitle("Predicted Treatment Effect (0-10 Scale)") ///
	xlabel(1 "Perspective Getting Condition" 2 "Informational Condition" 3 "Ideology", labsize(small)) ///
	note("N = 559 Republicans, 653 Democrats." "Estimates created using OLS. Results consistent with ordered logit model.", size(small)) 
	
graph export "C:\Users\Ryan\Documents\summer 2024\Perspective Taking Paper\figures\Fig1_randr.png", as(png) width(4000) replace


*figure 2

  eststo clear
drop flag
gen flag = 0 
replace flag = 1 if rep_condition == 1 & control == 1
replace flag = 1 if rep_condition == 1 & wm_pt == 1
replace flag = 1 if rep_condition == 1 & wm_it == 1
regress DV_rep_1 i.wm_pt c.affect i.wm_pt#c.affect wm_it white_nh male age_q education_q ideology if flag == 1, vce(robust)
margins, at(affect=(4 73) wm_pt=(0 1) wm_it=0)
margins, at(affect=(0(5)100) wm_pt=(0 1) wm_it=0)
	marginsplot,  ytitle("") xtitle("Affective Partisanship")  ///
	scheme(s1color) xlabel(4 "Bottom Quartile" 40 "Median" 73 "Top Quartile", labsize(small)) ///
	ylabel(4 "4 - More Unfair" 5 6 7 "7 - More Fair", angle(30) labsize(small)) legend(label(7 "Control") label(2 "Perspective Taking")) ///
	note("N = 553. Estimates created using OLS.", size(vsmall))

	
